home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / r2dbf121.zip / 2BYTEDAT.C next >
Text File  |  1991-02-18  |  2KB  |  63 lines

  1. #include "i:\clipper\nandef.h"
  2. #include "i:\clipper\extend.h"
  3. #include "i:\tc\include\stdlib.h"
  4.  
  5. void NumEnter( char s[], int num1, int pos );
  6. int  mystrlen( char s[]);
  7.  
  8. CLIPPER TwoByte()
  9. /* Convert a 2 byte to the data RBBS had for subscription and return
  10.    it in database DATE format, ie "19880101")                         */
  11. {
  12.    unsigned char subdate[2];
  13.    char thedate[9] = "        ";
  14.    div_t x;
  15.    int i, mo, da;
  16.  
  17.    strcpy (subdate, _parc(1));
  18.  
  19.    x  = div( subdate[0] & ( 1 ^ 255) , 2);
  20.    i  = x.quot + 1980;
  21.    x  = div( subdate[1], 32);
  22.    mo = x.quot | ((subdate[0] & 1) * 8);
  23.    da = (subdate[1] & ( 224 ^ 255 ));
  24. /*
  25.    i  = (subdate[0] & ( ~ 1 ) ) / 2 + 1980;
  26.    mo = (subdate[1] / 32) | ((subdate[0] & 1) * 8);
  27.    da = (subdate[1] & ( ~ 224 ) );
  28. */
  29.    NumEnter( thedate, i,  0);    /* put i  in 1st position(0),eg. 1980 */
  30.    NumEnter( thedate, mo, 4);    /* put mo in 5th position(4),eg. 01   */
  31.    NumEnter( thedate, da, 6);    /* put da in 7th position(6),eg. 31   */
  32.    _retds( thedate );
  33. }
  34.  
  35.  
  36. void NumEnter( char s[], int num1, int pos )
  37. /*
  38.    Convert the passed number to a string and
  39.    place in Clipper Date String
  40. */
  41. {
  42.   char temp[10];
  43.   int i,l;
  44.  
  45.   itoa(num1, temp,10);            /* int->string, radix=10 */
  46.   l = mystrlen(temp);
  47.   if (l == 1)
  48.   {
  49.       s[pos] = '0';
  50.       pos++;
  51.   }
  52.   for (i=0;temp[i]!='\0';i++)     /* put into s[]          */
  53.     s[pos+i] = temp[i];
  54.   return;
  55. }
  56.  
  57.  
  58. int mystrlen( char s[] )
  59. {
  60.   int i = 0;
  61.   while (s[i] != '\0') i++;
  62.   return (i);
  63. }